package com.hsav.kcxb.adapter.common;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.hsav.kcxb.adapter.common.AbsListManager;

import java.util.List;

/**
 * Created by zhao on 17-4-29.
 */

public class MyListBaseAdapter<T> extends BaseAdapter {

    private final Context mContext;
    private final LayoutInflater mLaoutInflater;
    private final AbsListManager mAbsListManager;
    private List<T> mDataList;

    public MyListBaseAdapter(Context context,AbsListManager absListManager){
        this.mContext = context;
        this.mAbsListManager = absListManager;
        this.mDataList = absListManager.getDataList();
        this.mLaoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        if(mDataList!=null){
            return mDataList.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        if(mDataList!=null){
            return mDataList.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int pos) {
        return pos;
    }

    @Override
    public View getView(int pos, View convertView, ViewGroup viewGroup) {
        if (convertView == null) {
            convertView = mLaoutInflater.inflate(mAbsListManager.getLayoutId(), viewGroup, false);
        }

        mAbsListManager.bindDataView(convertView,getItem(pos));
        return convertView;
    }
}
